﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;
using SharedGenomics.Annotations;

namespace SharedGenomics.Workbench.Annotations.Requests
{
    /// <summary>
    /// This request stage creates a google search annotation on the 'annotation target' for a request (i.e. the thing being annotated)
    /// If the request succeeds, the Annotation property of the <see cref="AnnotationRequestContext"/> will contain a <see cref="GoogleSearchAnnotation"/>
    /// </summary>
    public class GoogleSearchAnnotationRequestStage : IAnnotationRequestStage
    {
        public void Process(AnnotationRequestContext context, IAnnotationRequestPipelineTraversalStrategy traversalStrategy)
        {
            string searchTerm = context.AnnotationTarget as string;

            if (searchTerm != null)
            {
                //create search annotation only if the annotation target is a string
                //TODO: call ToString() and use that?
                context.AddAnnotation(new GoogleSearchAnnotation(searchTerm), new AnnotationValue(AnnotationKey.SnpName, searchTerm));
            }

            traversalStrategy.MoveNext(context);
        }
    }
}
